//
//  ShopConsultCell.m
//  sensen_ios
//
//  Created by pro on 16/2/25.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ShopConsultCell.h"

@interface ShopConsultCell ()
{
    ConsultModel *_model; // 数据类，从布局类处获取

}
@property (nonatomic, strong) UILabel *consulterLabel; // 网友

@property (nonatomic, strong) UILabel *contentLabel; // 咨询内容
@property (nonatomic, strong) UILabel *consultTime; // 咨询时间

@property (nonatomic, strong) UILabel *replyLabel; // 回复
@property (nonatomic, strong) UILabel *replyTime; // 回复时间




@end

@implementation ShopConsultCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self _createViews];
    }
    
    return self;
}


#pragma mark - 创建视图
- (void)_createViews {
    CGFloat x = 10;
    CGFloat y = 10;
    CGFloat width = 60;
    CGFloat height = 20;
    // 网友：
    UILabel *consulterTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    consulterTitleLabel.font = FONT(13);
    consulterTitleLabel.text = @"网       友:";
    consulterTitleLabel.textColor = [UIColor lightGrayColor];
    consulterTitleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:consulterTitleLabel];
    consulterTitleLabel.tag = 1;
    
    // 咨询内容：
    y = consulterTitleLabel.bottom;
    UILabel *contentTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    contentTitleLabel.font = FONT(13);
    contentTitleLabel.text = @"咨询内容:";
    contentTitleLabel.textColor = [UIColor grayColor];
    contentTitleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:contentTitleLabel];
    contentTitleLabel.tag = 2;
    
    // 森森回复：
    y = contentTitleLabel.bottom;
    UILabel *replyTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    replyTitleLabel.font = FONT(13);
    replyTitleLabel.text = @"森森回复:";
    replyTitleLabel.textColor = SS_NAVI_ORANGE_LIGHT_COLOR;
    replyTitleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:replyTitleLabel];
    replyTitleLabel.tag = 3;

    
    
    // 咨询时间
    width = 120;
    y = consulterTitleLabel.top;
    _consultTime = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _consultTime.font = FONT(12);
    _consultTime.text = @"2015-01-01 08:08:08";
    _consultTime.textColor = [UIColor lightGrayColor];
    _consultTime.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_consultTime];
    _consultTime.right = SCREEN_WIDTH - 10;
    _consultTime.width = [_consultTime.text getSizeOfString:12].width;
    
    // 网友名称
    x = consulterTitleLabel.right + 5;
    y = consulterTitleLabel.top;
    width = _consultTime.left - 10 - x;
    _consulterLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _consulterLabel.font = FONT(13);
    _consulterLabel.text = @"任性不认命";
    _consulterLabel.textColor = [UIColor lightGrayColor];
    _consulterLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_consulterLabel];
    
    // 咨询内容
    x = contentTitleLabel.right + 5;
    y = contentTitleLabel.top;
    width = SCREEN_WIDTH - 10 - x;
    _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _contentLabel.numberOfLines = 0;
    _contentLabel.font = FONT(13);
    _contentLabel.text = @"咨询内容";
    _contentLabel.textColor = [UIColor grayColor];
    _contentLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_contentLabel];
    
    // 森森回复
    x = replyTitleLabel.right + 5;
    y = replyTitleLabel.top;
    _replyLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _replyLabel.numberOfLines = 0;
    _replyLabel.font = FONT(13);
    _replyLabel.text = @"森森回复";
    _replyLabel.textColor = SS_NAVI_ORANGE_LIGHT_COLOR;
    _replyLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_replyLabel];
    
    
}

#pragma mark - 重写set
- (void)setLayout:(ConsultCellFrameLayout *)layout {
    // 获得model
    _layout = layout;
    _model = layout.model;
    
    // 设置属性并布局
    [self _setAttribute];
}
// 设置属性并布局
- (void)_setAttribute {
    
    // 设置咨询者（网友）的内容
    _consulterLabel.text = _model.consulterName;
    
    // 咨询时间设置
    _consultTime.text = [NSDate getDateStringFromeNumber:_model.consultTime];
    _consultTime.width = [_consultTime.text getSizeOfString:12].width;
    _consultTime.right = SCREEN_WIDTH - 10;
    
    // 咨询内容填充和高度设置
    _contentLabel.text = _model.consultContent;
    _contentLabel.height = _layout.contentHeight;
    
    // 森森回复内容填充和高度设置
    UILabel *replyTitleLabel = [self.contentView viewWithTag:3];
    replyTitleLabel.top = _contentLabel.bottom;
    
    _replyLabel.text = _model.sensenReply;
    _replyLabel.top = replyTitleLabel.top;
    _replyLabel.height = _layout.replyHeight;
}



@end
